package com.ruoyi.mes.service.impl;

import java.math.BigDecimal;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mes.domain.ProInfo;
import com.ruoyi.mes.mapper.ProInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mes.mapper.OuthouInfoMapper;
import com.ruoyi.mes.domain.OuthouInfo;
import com.ruoyi.mes.service.IOuthouInfoService;

/**
 * 出库信息Service业务层处理
 *
 * @author LongAndHao
 * @date 2023-04-04
 */
@Service
public class OuthouInfoServiceImpl implements IOuthouInfoService
{
    @Autowired
    private OuthouInfoMapper outhouInfoMapper;

    @Autowired
    private ProInfoMapper proInfoMapper;

    /**
     * 查询出库信息
     *
     * @param id 出库信息主键
     * @return 出库信息
     */
    @Override
    public OuthouInfo selectOuthouInfoById(Long id)
    {
        return outhouInfoMapper.selectOuthouInfoById(id);
    }

    /**
     * 查询出库信息列表
     *
     * @param outhouInfo 出库信息
     * @return 出库信息
     */
    @Override
    public List<OuthouInfo> selectOuthouInfoList(OuthouInfo outhouInfo)
    {
        List<OuthouInfo> infos = outhouInfoMapper.selectOuthouInfoList(outhouInfo);
        if (infos.size() != 0){
            for (OuthouInfo info : infos) {
                BigDecimal result = new BigDecimal("0.00");
                ProInfo proInfo = proInfoMapper.getProInfoByCode(info.getProCode());
                result = BigDecimal.valueOf(info.getProQuantity()).multiply(proInfo.getPrice());
                info.setBusinessVolume(result);
                outhouInfoMapper.updateOuthouInfo(info);
            }
        }
        return infos;
    }

    /**
     * 新增出库信息
     *
     * @param outhouInfo 出库信息
     * @return 结果
     */
    @Override
    public int insertOuthouInfo(OuthouInfo outhouInfo)
    {
        outhouInfo.setCreateTime(DateUtils.getNowDate());
        return outhouInfoMapper.insertOuthouInfo(outhouInfo);
    }

    /**
     * 修改出库信息
     *
     * @param outhouInfo 出库信息
     * @return 结果
     */
    @Override
    public int updateOuthouInfo(OuthouInfo outhouInfo)
    {
        outhouInfo.setUpdateTime(DateUtils.getNowDate());
        return outhouInfoMapper.updateOuthouInfo(outhouInfo);
    }

    /**
     * 批量删除出库信息
     *
     * @param ids 需要删除的出库信息主键
     * @return 结果
     */
    @Override
    public int deleteOuthouInfoByIds(Long[] ids)
    {
        return outhouInfoMapper.deleteOuthouInfoByIds(ids);
    }

    /**
     * 删除出库信息信息
     *
     * @param id 出库信息主键
     * @return 结果
     */
    @Override
    public int deleteOuthouInfoById(Long id)
    {
        return outhouInfoMapper.deleteOuthouInfoById(id);
    }
}
